import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;

@WebServlet(name="LoginServlet",urlPatterns = "/login.do",
        initParams = {@WebInitParam(name = "encoding",value = "UFT-8"),})
public class LoginServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        System.out.println("--------------初始化11111--------------------");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        ServletConfig config = this.getServletConfig();
//        String param = config.getInitParameter("encoding");
//
//        String username=req.getParameter("username");
//        String password=req.getParameter("password");
//
//        resp.setContentType("text/html;charset=utf-8");
//        PrintWriter out=resp.getWriter();
//        out.println("用户名："+username+"<br>");
//        out.println("密码："+password);
//
//        out.println("编码encoding："+param);
        //属性的读取123
        resp.setContentType("text/html;charset=utf-8");
        ServletContext context = this.getServletContext();
        System.out.println(context.getServerInfo().toString());
        PrintWriter out = resp.getWriter();
        InputStream in=context.getResourceAsStream("/WEB-INF/it.properties");
        Properties prop=new Properties();
        prop.load(in);
        out.println("url:"+prop.getProperty("url"));
        out.println("username:"+prop.getProperty("username"));
        out.println("password:"+prop.getProperty("password"));

        out.println("<a href='downfile'>下载查看</a>");
    }
}
